//
//  ConfigCellPhoneView.m
//  JinganMindCloud
//
//  Created by JinganMac on 2020/7/3.
//  Copyright © 2020 JingAn. All rights reserved.
//

#import "ConfigCellPhoneView.h"

@interface ConfigCellPhoneView ()
@property (nonatomic, strong) UILabel *leftTitleView;
@property (nonatomic, strong) UIImageView *phoneIcon;
@property (nonatomic, strong) UILabel *phonelabel;

@end

@implementation ConfigCellPhoneView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self addSubview:self.leftTitleView];
        self.phonelabel.userInteractionEnabled = YES;
        self.tapGestureRecognizer = [[UITapGestureRecognizer alloc]init];
        [self.phonelabel addGestureRecognizer:self.tapGestureRecognizer];
        @weakify(self)
        [self.tapGestureRecognizer.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            @strongify(self)
            if (self.baseVaule.length>0) {
                [MGJRouter openURL:@"MindCloud_Phone" withUserInfo:@{@"phoneNumber":self.phonelabel.text} completion:nil];
            }
        }];
    }
    return self;
}

-(void)layoutSubviews{
    
    [_leftTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(self);
        make.width.mas_equalTo(self.leftViewWidth);
    }];

}

-(UILabel *)phonelabel{
    if (!_phonelabel) {
        _phonelabel = [UILabel new];
        _phonelabel.textColor = [UIColor colorWithHexString:@"#326BD8"];
        _phonelabel.font = [UIFont systemFontOfSize:13.];
    }
    return _phonelabel;
}

-(UIImageView *)phoneIcon{
    if (!_phoneIcon) {
        _phoneIcon = [UIImageView new];
    }
    return _phoneIcon;
}

-(UILabel *)leftTitleView{
    if (!_leftTitleView) {
        _leftTitleView = [UILabel new];
        _leftTitleView.textColor = [UIColor colorWithHexString:@"#AEAEAE"];
        _leftTitleView.font = [UIFont systemFontOfSize:13.];
        _leftTitleView.numberOfLines = 0;
    }
    return _leftTitleView;
}

-(void)setViewConfiSets:(CellSubViewsConfigSetting *)viewConfiSets{
    self.leftTitleView.text = viewConfiSets.cTitleValue;
}

-(void)setBaseVaule:(NSString *)baseVaule{
    [super setBaseVaule:baseVaule];
    if (baseVaule.length>0) {
        [self addSubview:self.phoneIcon];
        [self addSubview:self.phonelabel];
        self.phonelabel.text = baseVaule;
        self.phoneIcon.image = [UIImage MCCImageNamed:@"newPhone"];
        [_phoneIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftTitleView.mas_right).offset(0);
            make.size.mas_equalTo(CGSizeMake(12, 13));
            make.centerY.mas_equalTo(self);
        }];
        
        [_phonelabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.phoneIcon.mas_right).offset(5);
            make.top.bottom.mas_equalTo(self);
            make.right.mas_equalTo(self);
        }];
    }else{
        [self addSubview:self.phonelabel];
        self.phoneIcon.image = nil;
        self.phonelabel.text = @"--";
        
        [_phonelabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.leftTitleView.mas_right).offset(0);
            make.top.bottom.mas_equalTo(self);
            make.right.mas_equalTo(self);
        }];
    }
}


@end
